package com.gitpractice.liwushuo.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gitpractice.liwushuo.R;
import com.gitpractice.liwushuo.adapter.CategoryAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * A simple {@link Fragment} subclass.
 */
public class CategoryFragment extends Fragment {


    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private List<Fragment> mFragmentList;
    private String[] mStrinfArray;

    public CategoryFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_category, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        initTabLayout(view);
    }

    private void initTabLayout(View view) {
        mTabLayout = (TabLayout) view.findViewById(R.id.tl_category);
        mViewPager = (ViewPager) view.findViewById(R.id.vp_category);
        initList();
        mViewPager.setAdapter(new CategoryAdapter(getFragmentManager(),mFragmentList,mStrinfArray));
        mTabLayout.setupWithViewPager(mViewPager);
    }

    private void initList() {
        mFragmentList=new ArrayList<>();
        mFragmentList.add(new GuideCategoryFragment());
        mFragmentList.add(new SingleCategoryFragment());
        mStrinfArray=getResources().getStringArray(R.array.tablayoutString);

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();

    }
}
